
package com.companymodule.servlet;
import com.companymodule.bean.TbCompanyProductMiddle;
import com.companymodule.dao.TbCompanyProductMiddleDAO;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import util.*;

public class TbCompanyProductMiddleServlet extends HttpServlet{
    public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method")==null?"":request.getParameter("method");
        if("add".equals(method)){
        int companyId=Integer.parseInt(request.getParameter("companyId"));
        int productId=Integer.parseInt(request.getParameter("productId"));
            if(new TbCompanyProductMiddleDAO().add(new TbCompanyProductMiddle(companyId,productId))){
            request.getSession().setAttribute("result", "添加成功");
            }else{            
            request.getSession().setAttribute("result", "添加失败");
            }
            goList(request, response);
        }
        if("del".equals(method)){
            if(UtilDAO.delin("Tb_CompanyProductMiddle", "CompanyProductMiddleId", request.getParameter("delIds"))){            
            request.getSession().setAttribute("result", "删除成功");
            }else{            
            request.getSession().setAttribute("result", "删除失败");
            }
            goList(request, response);
        }
        if("edit".equals(method)){
        int companyProductMiddleId=Integer.parseInt(request.getParameter("companyProductMiddleId"));
        int companyId=Integer.parseInt(request.getParameter("companyId"));
        int productId=Integer.parseInt(request.getParameter("productId"));
            if(new TbCompanyProductMiddleDAO().add(new TbCompanyProductMiddle(companyProductMiddleId,companyId,productId))){
            request.getSession().setAttribute("result", "修改成功");
            }else{            
            request.getSession().setAttribute("result", "修改失败");
            }
            goList(request, response);
        }
        if ("list".equals(method)) goList(request, response);
        if ("listById".equals(method)) {
            request.getSession(true).setAttribute("tbCompanyProductMiddle",new TbCompanyProductMiddleDAO().getTbCompanyProductMiddleByCompanyProductMiddleId(Integer.parseInt(request.getParameter("companyProductMiddleId"))));
            response.sendRedirect("CompanyModule/TbCompanyProductMiddleOperate.jsp");
    	}
        if("showadd".equals(method)){
            request.getSession(true).removeAttribute("tbCompanyProductMiddle");
            response.sendRedirect("CompanyModule/TbCompanyProductMiddleOperate.jsp");
        }
    }
    public void goList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	request.getSession(true).setAttribute("tbCompanyProductMiddleList",new TbCompanyProductMiddleDAO().getTbCompanyProductMiddleAll());
        response.sendRedirect("CompanyModule/TbCompanyProductMiddleList.jsp");
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doGet
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doPost
}
